/*     */ package com.qmsk.business.member.memberLevel.controller;
/*     */ 
/*     */ import com.qmsk.business.member.memberLevel.dao.MemberLevelDAO;
/*     */ import com.qmsk.business.shopList.ShopMap;
/*     */ import com.utils.basic.ObjectComm;
/*     */ import com.utils.gson.in.GsonHeadOneRow;
/*     */ import com.utils.gson.out.GsonEbRst;
/*     */ import com.utils.gson.out.GsonEbRstData;
/*     */ import com.utils.http.HttpGsonPtResponseUtils;
/*     */ import com.utils.jdbc.connection.DbConnection;
/*     */ import com.utils.web.RequestUtils;
/*     */ import com.utils.web.ResponseUtils;
/*     */ import java.io.IOException;
/*     */ import java.sql.SQLException;
/*     */ import java.util.ArrayList;
/*     */ import java.util.List;
/*     */ import javax.servlet.http.HttpServletRequest;
/*     */ import javax.servlet.http.HttpServletResponse;
/*     */ import org.apache.log4j.Logger;
/*     */ import org.springframework.beans.factory.annotation.Autowired;
/*     */ import org.springframework.stereotype.Controller;
/*     */ import org.springframework.transaction.annotation.Transactional;
/*     */ import org.springframework.web.bind.annotation.PathVariable;
/*     */ import org.springframework.web.bind.annotation.RequestMapping;
/*     */ 
/*     */ @Controller
/*     */ @RequestMapping({"/memberLevel"})
/*     */ public class MemberLevelController
/*     */ {
/*  34 */   private static final Logger logger = Logger.getLogger(MemberLevelController.class);
/*     */ 
/*     */   @Autowired
/*     */   private MemberLevelDAO dao;
/*     */ 
/*     */   @RequestMapping(value={"find/shopId/{shopId}/{pageIdx}/{pageSize}"}, method={org.springframework.web.bind.annotation.RequestMethod.GET})
/*     */   public void getListAll(HttpServletRequest request, HttpServletResponse response, @PathVariable("shopId") Integer shopId, @PathVariable("pageIdx") Integer nPageIdx, @PathVariable("pageSize") Short nPageSize)
/*     */   {
/*  60 */     nPageSize = RequestUtils.getRequestValidPageSize(nPageSize);
/*     */     try {
/*  62 */       GsonEbRst gsonEbRst = this.dao.getGsonOfShopId(shopId, nPageIdx, 
/*  63 */         nPageSize);
/*  64 */       ResponseUtils.setResponseResult(gsonEbRst, response);
/*     */     } catch (SQLException e) {
/*  66 */       logger.error(e);
/*  67 */       ResponseUtils.setErrorMsgResponse(
/*  68 */         RequestUtils.getFindDataErrorMessage(request), response);
/*     */     }
/*     */   }
/*     */ 
/*     */   @RequestMapping(value={"find/wx/shopId/{shopId}/{pageIdx}/{pageSize}"}, method={org.springframework.web.bind.annotation.RequestMethod.GET})
/*     */   public void getWxListAll(HttpServletRequest request, HttpServletResponse response, @PathVariable("shopId") Integer shopId, @PathVariable("pageIdx") Integer nPageIdx, @PathVariable("pageSize") Short nPageSize)
/*     */   {
/*  87 */     nPageSize = RequestUtils.getRequestValidPageSize(nPageSize);
/*     */     try {
/*  89 */       GsonEbRst gsonEbRst = this.dao.getWxGsonOfShopId(shopId, nPageIdx, 
/*  90 */         nPageSize);
/*  91 */       ResponseUtils.setResponseResult(gsonEbRst, response);
/*     */     } catch (SQLException e) {
/*  93 */       logger.error(e);
/*  94 */       ResponseUtils.setErrorMsgResponse(
/*  95 */         RequestUtils.getFindDataErrorMessage(request), response);
/*     */     }
/*     */   }
/*     */ 
/*     */   @RequestMapping(value={"find/shopId/{shopId}/normal"}, method={org.springframework.web.bind.annotation.RequestMethod.GET})
/*     */   public void getListNormal(HttpServletRequest request, HttpServletResponse response, @PathVariable("shopId") Integer shopId)
/*     */   {
/*     */     try
/*     */     {
/* 113 */       GsonEbRst gsonEbRst = this.dao.getGsonOfNormal(shopId);
/* 114 */       ResponseUtils.setResponseResult(gsonEbRst, response);
/*     */     } catch (SQLException e) {
/* 116 */       logger.error(e);
/* 117 */       ResponseUtils.setErrorMsgResponse(
/* 118 */         RequestUtils.getFindDataErrorMessage(request), response);
/*     */     }
/*     */   }
/*     */ 
/*     */   @RequestMapping(value={"find/shopId/{shopId}/sys"}, method={org.springframework.web.bind.annotation.RequestMethod.GET})
/*     */   public void getListShopIdSys(HttpServletRequest request, HttpServletResponse response, @PathVariable("shopId") Long shopId)
/*     */   {
/*     */     try {
/* 126 */       GsonEbRst gsonEbRst = this.dao.getGsonOfShopIdSys(shopId);
/* 127 */       ResponseUtils.setResponseResult(gsonEbRst, response);
/*     */     } catch (SQLException e) {
/* 129 */       logger.error(e);
/* 130 */       ResponseUtils.setErrorMsgResponse(
/* 131 */         RequestUtils.getFindDataErrorMessage(request), response);
/*     */     }
/*     */   }
/*     */ 
/*     */   @RequestMapping(value={"find/shopId/{shopId}/normal/{pageIdx}/{pageSize}"}, method={org.springframework.web.bind.annotation.RequestMethod.GET})
/*     */   public void getListNormal(HttpServletRequest request, HttpServletResponse response, @PathVariable("shopId") Integer shopId, @PathVariable("pageIdx") Integer nPageIdx, @PathVariable("pageSize") Short nPageSize)
/*     */   {
/* 150 */     nPageSize = RequestUtils.getRequestValidPageSize(nPageSize);
/*     */     try {
/* 152 */       GsonEbRst gsonEbRst = this.dao.getGsonOfNormal(shopId, nPageIdx, 
/* 153 */         nPageSize);
/* 154 */       ResponseUtils.setResponseResult(gsonEbRst, response);
/*     */     } catch (SQLException e) {
/* 156 */       logger.error(e);
/* 157 */       ResponseUtils.setErrorMsgResponse(
/* 158 */         RequestUtils.getFindDataErrorMessage(request), response);
/*     */     }
/*     */   }
/*     */ 
/*     */   @Transactional
/*     */   @RequestMapping(value={"insert/shopId/{shopId}"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
/*     */   public void insert(HttpServletRequest request, HttpServletResponse response, @PathVariable("shopId") Long shopId)
/*     */   {
/*     */     try
/*     */     {
/* 176 */       int nResult = 0;
/* 177 */       GsonHeadOneRow r = GsonHeadOneRow.jsonStrToObject(
/* 178 */         RequestUtils.getStringOfData(request));
/* 179 */       Integer sys = ObjectComm.objectToInteger(r.getValueOfName("sys"));
/* 180 */       if ((sys != null) && (1 == sys.intValue())) {
/* 181 */         this.dao.updateSysValueOfShopId(shopId);
/*     */       }
/*     */ 
/* 185 */       if (this.dao.insertGsonHeadOneRow(r) > 0) {
/* 186 */         Long id = this.dao.getLastId();
/* 187 */         r.autoAddHeadData("id", id);
/* 188 */         if ((id != null) && (id.longValue() > 0L)) {
/* 189 */           GsonEbRst g = insertToPt(r.objectToJsonStr(), response, id, 
/* 190 */             shopId);
/* 191 */           if ((g != null) && (g.getState() == 0)) {
/* 192 */             nResult = 1;
/*     */           }
/*     */         }
/*     */       }
/* 196 */       if (nResult > 0) {
/* 197 */         DbConnection.commit();
/* 198 */         ResponseUtils.setSqlResultResponse(nResult, 
/* 199 */           RequestUtils.getSqlInsertDataErrorMessage(request), 
/* 200 */           response);
/* 201 */         return; }
/* 202 */       DbConnection.rollback();
/* 203 */       ResponseUtils.setErrorMsgResponse(
/* 204 */         RequestUtils.getSqlInsertDataErrorMessage(request), 
/* 205 */         response);
/*     */     }
/*     */     catch (Exception e) {
/* 208 */       DbConnection.rollback();
/* 209 */       logger.error(e);
/* 210 */       ResponseUtils.setErrorMsgResponse(
/* 211 */         RequestUtils.getSqlInsertDataErrorMessage(request) + ":" + 
/* 212 */         e.getMessage(), response);
/*     */     }
/*     */   }
/*     */ 
/*     */   private GsonEbRst insertToPt(String sGsonInData, HttpServletResponse response, Long id, Long shopId)
/*     */     throws Exception
/*     */   {
/* 219 */     GsonEbRst rst = null;
/* 220 */     Long outId = ShopMap.getOutIdOfShopId(shopId);
/* 221 */     if ((outId != null) && (outId.longValue() > 0L)) {
/* 222 */       String requestData = "id=" + id + "&" + 
/* 223 */         "data" + "=" + sGsonInData;
/* 224 */       rst = HttpGsonPtResponseUtils.postPtEbRst(
/* 225 */         "ptMemlevel/insert/shopId/" + outId, requestData, response);
/* 226 */       if (rst != null) {
/* 227 */         return rst;
/*     */       }
/* 229 */       logger.error("Synchronous data failed[crm/pt-MemberLevel]:" + 
/* 230 */         requestData);
/*     */     }
/*     */ 
/* 233 */     return null;
/*     */   }
/*     */ 
/*     */   private GsonEbRst getPtMemberLevelDelEbRst(String id, Long shopId, HttpServletResponse response) throws Exception
/*     */   {
/* 238 */     String sData = "id=" + id;
/* 239 */     Long outId = ShopMap.getOutIdOfShopId(shopId);
/* 240 */     if ((outId != null) && (outId.longValue() > 0L)) {
/* 241 */       String sUrl = "ptMemlevel/del/shopId/" + outId;
/* 242 */       GsonEbRst rst = HttpGsonPtResponseUtils.postPtEbRst(sUrl, sData, 
/* 243 */         response);
/* 244 */       if (rst != null) {
/* 245 */         return rst;
/*     */       }
/*     */     }
/* 248 */     return null;
/*     */   }
/*     */ 
/*     */   @Transactional
/*     */   @RequestMapping(value={"del/shopId/{shopId}"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
/*     */   public void delete(HttpServletRequest request, HttpServletResponse response, @PathVariable("shopId") Long shopId)
/*     */   {
/* 262 */     String id = RequestUtils.getStringOfId(request);
/*     */     try {
/* 264 */       int nResult = 0;
/* 265 */       String[] strParams = id.split(",");
/* 266 */       List paramsList = new ArrayList();
/* 267 */       for (String s : strParams) {
/* 268 */         GsonEbRst gson = this.dao.getSys(Long.valueOf(s), Boolean.valueOf(true));
/* 269 */         if (gson.getResult().isExistsData()) {
/* 270 */           ResponseUtils.setErrorMsgResponse("默认入会，不可删除", response);
/* 271 */           return;
/*     */         }
/* 273 */         paramsList.add(new Object[] { s });
/*     */       }
/* 275 */       GsonEbRst rst = getPtMemberLevelDelEbRst(id, shopId, response);
/* 276 */       if ((rst != null) && (rst.getState() == 0)) {
/* 277 */         nResult = this.dao.deleteHeadData(new String[] { "ID" }, 
/* 278 */           paramsList);
/* 279 */         if (nResult > 0)
/* 280 */           DbConnection.commit();
/*     */         else {
/* 282 */           DbConnection.rollback();
/*     */         }
/*     */       }
/* 285 */       ResponseUtils.setSqlResultResponse(nResult, 
/* 286 */         RequestUtils.getSqlDeleteDataErrorMessage(request), 
/* 287 */         response);
/*     */     } catch (Exception e) {
/* 289 */       DbConnection.rollback();
/* 290 */       logger.error(e);
/* 291 */       ResponseUtils.setErrorMsgResponse(
/* 292 */         RequestUtils.getSqlDeleteDataErrorMessage(request) + ":" + 
/* 293 */         e.getMessage(), response);
/*     */     }
/*     */   }
/*     */ 
/*     */   @Transactional
/*     */   @RequestMapping(value={"edit/shopId/{shopId}"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
/*     */   public void update(HttpServletRequest request, HttpServletResponse response, @PathVariable("shopId") Long shopId)
/*     */   {
/* 311 */     String id = request.getParameter("id");
/* 312 */     String sDate = RequestUtils.getString(request, "data");
/*     */     try {
/* 314 */       GsonHeadOneRow g = GsonHeadOneRow.jsonStrToObject(sDate);
/* 315 */       String status = null;
/* 316 */       Integer sys = null;
/* 317 */       if (g == null) {
/* 318 */         ResponseUtils.setErrorMsgResponse("请求错误", response);
/* 319 */         return;
/*     */       }
/* 321 */       status = (String)g.getValueOfName("Status");
/* 322 */       sys = ObjectComm.objectToInteger(g.getValueOfName("sys"));
/*     */ 
/* 324 */       GsonEbRst gsonStatus = this.dao.getSys(Long.valueOf(Long.parseLong(id)), null);
/* 325 */       if ((!(gsonStatus.isExistsData())) && (status == null)) {
/* 326 */         ResponseUtils.setErrorMsgResponse("请先启用会员卡", response);
/* 327 */         return;
/*     */       }
/*     */ 
/* 331 */       if ((status != null) && ("停用".equals(status))) {
/* 332 */         GsonEbRst gson = this.dao.getSys(Long.valueOf(Long.parseLong(id)), Boolean.valueOf(true));
/* 333 */         if (gson.isExistsData()) {
/* 334 */           ResponseUtils.setErrorMsgResponse("唯一默认入会，不可修改", response);
/* 335 */           return;
/*     */         }
/*     */ 
/*     */       }
/*     */ 
/* 341 */       if (sys != null) {
/* 342 */         if (sys.intValue() == 1) {
/* 343 */           this.dao.updateSysValueOfShopId(shopId);
/* 344 */         } else if (sys.intValue() == 0) {
/* 345 */           ResponseUtils.setErrorMsgResponse("唯一默认入会，不可修改", response);
/* 346 */           return;
/*     */         }
/*     */       }
/*     */ 
/* 350 */       int nResult = this.dao.updateJsonOneRow(g, id);
/* 351 */       if (nResult > 0) {
/* 352 */         GsonEbRst rst = getPtMemberLevelEdit(id, shopId, sDate, 
/* 353 */           response);
/* 354 */         if ((rst != null) && (rst.getState() == 0))
/* 355 */           DbConnection.commit();
/*     */         else {
/* 357 */           DbConnection.rollback();
/*     */         }
/*     */       }
/* 360 */       ResponseUtils.setSqlResultResponse(nResult, 
/* 361 */         RequestUtils.getSqlUpdateDataErrorMessage(request), 
/* 362 */         response);
/*     */     } catch (Exception e) {
/* 364 */       DbConnection.rollback();
/* 365 */       logger.error(e);
/* 366 */       ResponseUtils.setErrorMsgResponse(
/* 367 */         RequestUtils.getSqlUpdateDataErrorMessage(request) + ":" + 
/* 368 */         e.getMessage(), response);
/*     */     }
/*     */   }
/*     */ 
/*     */   private GsonEbRst getPtMemberLevelEdit(String id, Long shopId, String sDate, HttpServletResponse response) throws IOException
/*     */   {
/* 374 */     String sData = "data=" + sDate + "&" + "id" + 
/* 375 */       "=" + id;
/* 376 */     Long outId = ShopMap.getOutIdOfShopId(shopId);
/* 377 */     if ((outId != null) && (outId.longValue() > 0L)) {
/* 378 */       String sUrl = "ptMemlevel/edit/shopId/" + outId;
/* 379 */       GsonEbRst rst = HttpGsonPtResponseUtils.postPtEbRst(sUrl, sData, 
/* 380 */         response);
/* 381 */       if (rst != null) {
/* 382 */         return rst;
/*     */       }
/*     */     }
/* 385 */     return null;
/*     */   }
/*     */ }

/* Location:           C:\Users\Administrator\Desktop\新建文件夹\WEB-INF\classes\
 * Qualified Name:     com.qmsk.business.member.memberLevel.controller.MemberLevelController
 * JD-Core Version:    0.5.3
 */